#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
VX Battle - 微信小游戏原型 (GUI版本)
主入口文件
"""

import sys
import os
import tkinter as tk
from tkinter import messagebox

# 添加src目录到Python路径
src_path = os.path.join(os.path.dirname(__file__), 'src')
if src_path not in sys.path:
    sys.path.insert(0, src_path)

try:
    from game.game_manager import GameManager
    from ui.main_window import MainWindow
except ImportError as e:
    # 如果导入失败，显示错误信息
    root = tk.Tk()
    root.withdraw()
    messagebox.showerror("导入错误", f"无法导入必要模块: {e}")
    sys.exit(1)

def main():
    """主函数"""
    try:
        # 初始化游戏管理器
        game_manager = GameManager()
        
        # 创建并运行主窗口
        app = MainWindow(game_manager)
        app.run()
        
    except KeyboardInterrupt:
        print("\n游戏被用户中断")
    except Exception as e:
        print(f"游戏运行出错: {e}")
        import traceback
        traceback.print_exc()
    finally:
        print("游戏已关闭")

if __name__ == "__main__":
    main()